/*
* @Author: slp
* @Date:   2018-07-05 16:26:24
* @Last Modified by:   ystlong
* @Last Modified time: 2018-07-21 02:55:14
*/
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <barelib.h>


void sve_inst_test()
{
	asm("add z1.h, z1.h, #10;"
	"ld1d {z1.d}, p1/Z, [x3, #0x0, MUL VL]");
}

float sve_code_test()
{
	int i = 0;
	float a[128];
	for (i=0; i<64; i++) {
		a[i] = a[i] + a[i+64];
	}
	return a[i];
}


int main() {
	char buf[128];
	int a = sqrt(2);
	long l1;
	printf("long size:%d, p: %p\n", sizeof(l1), &l1);
	memset(buf, 0, sizeof(buf));
	printf("dd: %p, %p\n", buf, &a);
	for(int i=0; i<10; i++) {
		printf("---: %d\n", i);
		printf("====\n");
		printf("%p\n", buf);
		printf("%d\n", i);
		strcmp("aaa", "bbb");
		strcmp("aaa", buf);
		printf("%p: %p\n", buf, &i);
		int res = sprintf(buf, "%ld", l1);
		assert(res < sizeof(buf));
		printf("%s\n", buf);
	}
	void *tt = NULL;
	tt = malloc(20);

	printf("malloc-test: %p\n", tt);
	free(tt);
	
	tt = malloc(20);
	printf("malloc-test: %p\n", tt);
	free(tt);
	tt = malloc(20);
	printf("malloc-test: %p\n", tt);
	free(tt);
	
	long freq = 3.5 * 10e6; /* 假设的系统频率, 只是为了方便计数*/
	printf("freq: %d\n", freq);

	/* 读取设置的系统频率 */
	long frq = read_frq();
	
	long lastcount = 0;
	long lasttime = 0;
	printf("system frq: %ld\n", frq);

	sve_inst_test();
	float sve_res = sve_code_test();
	printf("sve_res: %f\n", sve_res);

	while(1) {
		/* 读取当前tick计数值 */
		long count = read_counter();
		long cur_time = count / freq;
		if (cur_time - lasttime >= 1) {
			printf("cur tick: %d\n", cur_time);
			lasttime = cur_time;
		}
	}
    return 0;
}
